import { ListNode } from "./ListNode"

/**
 * 反转链表
 * @param head 头节点
 * @returns ListNode | null
 */
function reverseList(head: ListNode | null): ListNode | null {
  let p1 = head
  let p2: ListNode | null = null
  while (p1) {
    // 存储下一节点
    let temp = p1.next
    p1.next = p2
    p2 = p1
    p1 = temp
  }
  return p2
}